<?php

include_once ('class/class.koneksi.php');

class anggota {

    private $con;
	

    public function __construct() {
        $konek = new koneksi_db();
        $konek->koneksi();
        $this->con = $konek->con;
    }
	
	function getAllanggota() { //code coba2...
		$hasil = array();
		$temp = array();
        $query=$this->con->query("SELECT a.foto foto, a.spa spa, a.tahun_angkatan tahun, a.nama nama, a.nama_tenar tenar, a.hape hape,	a.email email, b.korwil korwil
									from anggota a left join korwil b on a.korwil = b.kd_korwil");
		$query->execute();
		$i = 0;
		while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
			$temp[$i][0] = $row['foto'];
			$temp[$i][1] = $row['spa'];
			$temp[$i][2] = $row['tahun'];
			$temp[$i][3] = $row['nama'];
			$temp[$i][4] = $row['tenar'];
			$temp[$i][5] = $row['hape'];
			$temp[$i][6] = $row['email'];
			$temp[$i][7] = $row['korwil'];
			$i++;
		}
		return $temp;
    }
	
	function getDetil($spa) { //code asli
		$query=$this->con->query("SELECT a.foto, a.spa, a.tahun_angkatan, a.nama, a.nama_tenar, a.tempat_lahir,
									a.tanggal_lahir, a.agama, a.alamat_rumah, a.telp_rumah, a.hape, a.hape2, 
									a.email, a.email2, a.kantor, a.alamat_kantor, a.telp_kantor, a.facebook,
									a.twitter, b.korwil, c.subkorwil	from anggota a join korwil b join subkorwil c on a.korwil = b.kd_korwil and a.subkorwil = c.kd_subkorwil and a.spa='$spa'");
		$query->execute();
		$i = 0;
		while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
			$temp[$i][0] = $row['foto'];
			$temp[$i][1] = $row['spa'];
			$temp[$i][2] = $row['tahun_angkatan'];
			$temp[$i][3] = $row['nama'];
			$temp[$i][4] = $row['nama_tenar'];
			$temp[$i][5] = $row['tempat_lahir'];
			$temp[$i][6] = $row['tanggal_lahir'];
			$temp[$i][7] = $row['agama'];
			$temp[$i][8] = $row['alamat_rumah'];
			$temp[$i][9] = $row['telp_rumah'];
			$temp[$i][10] = $row['hape'];
			$temp[$i][11] = $row['hape2'];
			$temp[$i][12] = $row['email'];
			$temp[$i][13] = $row['email2'];
			$temp[$i][14] = $row['kantor'];
			$temp[$i][15] = $row['alamat_kantor'];
			$temp[$i][16] = $row['telp_kantor'];
			$temp[$i][17] = $row['facebook'];
			$temp[$i][18] = $row['twitter'];
			$temp[$i][19] = $row['korwil'];
			$temp[$i][20] = $row['subkorwil'];
		}
		return $temp;
    }
	
	function getKorwil($korwil) {
		//$daftar_anggota=array();
        $query=$this->con->query("SELECT a.foto as foto, a.spa as spa, a.tahun_angkatan, a.nama, a.nama_tenar, a.hape,	a.email, b.korwil
									from anggota a left join korwil b on a.korwil = b.kd_korwil and a.korwil ='$korwil'");
		
		$query->execute();
		$i = 0;
		while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
			$temp[$i][0] = $row['foto'];
			$temp[$i][1] = $row['spa'];
			$temp[$i][2] = $row['tahun_angkatan'];
			$temp[$i][3] = $row['nama'];
			$temp[$i][4] = $row['nama_tenar'];
			$temp[$i][5] = $row['hape'];
			$temp[$i][6] = $row['email'];
			$temp[$i][7] = $row['korwil'];
			$i++;
		}
		return $temp;
    }
	
	function daftar_korw(){
		$query=$this->con->query("SELECT kd_korwil, korwil from korwil");
		
		$query->execute();
		$i = 0;
		while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
			$temp[$i][0] = $row['kd_korwil'];
			$temp[$i][1] = $row['korwil'];
			$i++;
		}
		return $temp;
	}
	
	function updateAnggota($foto, $spa, $tahun_angkatan, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil){
	
		$tgl_ubah=date('Y-m-d');
		 $query=$this->con->prepare("update anggota set foto = ?, spa = ?, tahun_angkatan = ?, nama = ?, nama_tenar = ?, tempat_lahir = ?,
									tanggal_lahir = ?, agama = ?, alamat_rumah = ?, telp_rumah = ?, hape = ?, hape2 = ?, 
									email = ?, email2 = ?, kantor = ?, alamat_kantor = ?, telp_kantor = ?, facebook = ?,
									twitter = ?, korwil = ?, subkorwil = ?");
		$isi = array($foto, $spa, $tahun_angkatan, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil);
		$query->execute($isi);
		$jml_data=$query->rowCount();
		return $jml_data;
	}
	
	function updatePersonal($foto, $spa, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil){
	
		$tgl_ubah=date('Y-m-d');
		 $query=$this->con->prepare("update anggota where foto = ?, spa = ?, tahun_angkatan = ?, nama = ?, nama_tenar = ?, tempat_lahir = ?,
									tanggal_lahir = ?, agama = ?, alamat_rumah = ?, telp_rumah = ?, hape = ?, hape2 = ?, 
									email = ?, email2 = ?, kantor = ?, alamat_kantor = ?, telp_kantor = ?, facebook = ?,
									twitter = ?, korwil = ?, subkorwil = ? where spa = $spa");
		$isi = array($foto, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil);
		$query->execute($isi);
		$jml_data=$query->rowCount();
		return $jml_data;
	}
	
	function rekamAnggota($foto, $spa, $tahun_angkatan, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil){
	
		$query=$this->con->prepare("INSERT INTO anggota (foto, spa, tahun_angkatan, nama, nama_tenar, tempat_lahir,
									tanggal_lahir, agama, alamat_rumah, telp_rumah, hape, hape2, 
									email, email2, kantor, alamat_kantor, telp_kantor, facebook,
									twitter, korwil, subkorwil) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		
		$isi = array($foto, $spa, $tahun_angkatan, $nama, $nama_tenar, $tempat_lahir, $tanggal_lahir, $agama, $alamat_rumah, $telp_rumah, $hape, $hape2, $email, $email2, $kantor, $alamat_kantor, $telp_kantor, $facebook, $twitter, $korwil, $subkorwil);
		$query->execute($isi);
        $jml_data=$query->rowCount();
        return$jml_data;
	}
	
}

?>